function outp = ReentryDynamic(state,ctrl)
    global m S R0 rot g0
    rad  = state(1);
    lat = state(3);
    V = state(4);
    fpa = state(5);
    azi = state(6);

    alt = rad - R0;
    [~,sonic,~,rho] = atmoscoesa(alt);

    alpha = ctrl(1);
    absBank = ctrl(2);
    signOfBank = ctrl(3);
    bank = absBank*signOfBank;
    Ma = V/sonic;
    [CL, CD] = getCLCD(alpha, Ma);
    q = 0.5*rho*V^2;
    D = q*S*CD;
    L = q*S*CL;

    raddot   = V*sin(fpa);
    londot   = V*cos(fpa)*sin(azi)/(rad*cos(lat));
    latdot   = V*cos(fpa)*cos(azi)/rad;
    speeddot = -D/m - g0*sin(fpa) + rot^2*rad*cos(lat)*(sin(fpa)*cos(lat)-cos(fpa)*sin(lat)*cos(azi));
    fpadot   = L*cos(bank)/(m*V) + cos(fpa)*(V/rad - g0/V) + 2*rot*cos(lat)*sin(azi)...
          + rot^2*rad*cos(lat)*(cos(fpa)*cos(lat) + sin(fpa)*cos(azi)*sin(lat))/V;
    azidot   = L*sin(bank)/(m*V*cos(fpa)) + V*cos(fpa)*sin(azi)*tan(lat)/rad +...
        2*rot*(sin(lat)-tan(fpa)*cos(lat)*cos(azi)) + rot^2*rad*sin(azi)*sin(lat)*cos(lat)/(V*cos(fpa));
    outp  = [raddot, londot, latdot, speeddot, fpadot, azidot];
end